<template>
  <div class="container">
    <img src="@/assets/img/car.png" alt="">
    <div class="search">

      <!-- <span style="margin-right:5px;">驾照类型</span> -->
      <span style="margin-right:5px;">车牌</span>
      <el-input placeholder="车牌" v-model="searchForm.plate"  style="margin-right:10px;width:250px"></el-input>
      <span style="margin-right:5px;">车型</span>
      <el-input placeholder="车型" v-model="searchForm.model"  style="margin-right:10px;width:250px"></el-input>
      <span style="margin-right:5px;">教练</span>
      <el-input placeholder="教练" v-model="searchForm.coach" style="margin-right:10px;width:250px"></el-input>
      <el-button type="primary" @click="search">查询</el-button>
     
      
      
      
       
     

      
     
  

    </div>
    <div class="list">
     <div class="wrapper" v-for="(item,index) in carList" :key="index" @click="getcarInfo(item.id)">
      <div class="little">
        <img :src="item.img" alt="">
        <div >{{item.plate}}</div>
      </div>
     </div>
    
     <el-pagination class="fenye"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[6, 8]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>
    </div>
    <el-dialog title="车辆信息" :visible.sync="infoStatus" width="50%">
      <el-form :model="info">
        <el-form-item style="width: 600px" label="头像">
          <el-upload
            class="avatar-uploader"
            action="https://jsonplaceholder.typicode.com/posts/"
            :show-file-list="false"
          >
            <img v-if="info.img" :src="info.img" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="车辆类型">
          <el-input disabled v-model="info.plate"></el-input>
        </el-form-item>
        <el-form-item label="准驾车型">
          <el-input disabled v-model="info.model" placeholder="请输入姓名"></el-input>
        </el-form-item>
        <el-form-item label="颜色">
          <el-input disabled v-model="info.color" placeholder="请输入姓名"></el-input>
        </el-form-item>
        <el-form-item label="教练">
          <el-input disabled v-model="info.coach" placeholder="请输入姓名"></el-input>
        </el-form-item>
        <el-form-item label="车辆状态">
          <el-input disabled v-model="info.status" placeholder="请输入姓名"></el-input>
        </el-form-item>
      </el-form>
     
    </el-dialog>
  </div>
  
</template>

<script>
import { carList ,carInfo,searchCar} from "@/api/car";
export default {
    name:'Car',
    data(){
      return{
          infoStatus:false,
          type:'',
          total:0,
          carList: [],
          pageNumber: 1, //当前页
          pagesize: 6, //分页的数据
          info:{},
          searchForm:{
            plate:null,
            model:null,
            coach:null
          }
        
      }
    },
    methods:{
      handleSizeChange(val) {
      this.pagesize = val;
      this.getCarList()
    },
    handleCurrentChange(val) {
      this.pageNumber = val;
      this.getCarList()
    },
    async getCarList() {
      let res = await carList({
        pagesize: this.pagesize,
        pageNumber: this.pageNumber,
      });
      if (res.code == 200) {
        this.carList = res.data;
        this.total = res.totalCount;
      }
    },
   async getcarInfo(id){
    this.infoStatus = true
    let res =await carInfo(id)
    if(res.code==200){
      this.info = res.data
    }
   },
   async search() {
      if (this.searchForm.plate == "") this.searchForm.plate = null;
      if (this.searchForm.model == "") this.searchForm.model = null;
      if (this.searchForm.coach == "") this.searchForm.coach = null;
      if (this.searchForm.plate == null && this.searchForm.model==null&&this.searchForm.coach==null){
        this.getCarList()
        return
      }
     
      let res = await searchCar(this.searchForm);
      if (res.code == 200) {
        this.$message({
          message: res.message,
          type: "success",
        });
        this.carList = res.data;
        this.total = res.data.length;
      }
     
     
    },
    },
    mounted() {
      this.getCarList()
    },
}
</script>

<style scoped lang="scss">
.container{
  width: 87%;
 
  box-shadow: 4px 4px 15px rgb(136, 116, 116);
  margin-left: 40px;
  padding: 20px 0;
  box-sizing: border-box;
  img{
    width: 100%;
  }
  .search{
    background-color: #999d9c;
    width: 100%;
    height: 60px;
    display: flex;
    line-height: 60px;
    padding-left: 200px;
    color: #ffffff;
    align-items: center;
    
    
  }
  .list{
    position: relative;
    width: 100%;
    height: 600px;
    padding-left: 10px;
    padding-top: 10px;
    padding-right: 10px;
    display: flex;
    
    flex-wrap: wrap;
    .fenye{
      position: absolute;
      bottom: 10px;
      left: 30%;
    }
    .wrapper{
      width: 250px;
      height: 250px;
      border: solid 5px #999d9c;
      border-radius: 10px;
      margin-left: 30px;
     
      .little{
        width: 90%;
        height: 90%;
        background-color: #999d9c;
        margin-top: 5%;
        margin-left: 5%;
        img{
          width: 100%;
          height: 80%;
        }
        div{
          text-align: center;
          line-height: 30px;
        }
       
        
        
      }
      
    }
  }

}
</style>